package com.lianniu.web.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.lianniu.web.util.FileUploadUtil;

@Controller
@RequestMapping("/baidu")
public class BaiduFileController {

	@Autowired
	FileUploadUtil fileUpload;
	  @RequestMapping(value="/uploadFile",method={RequestMethod.GET,RequestMethod.POST})
      public @ResponseBody String uploadFile(@RequestParam(value = "upfile", required = false) MultipartFile upfile,HttpServletRequest req){
		  Date day = new Date();
		  
		  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		  String s = sdf.format(day);
		  String imgPath =fileUpload.getPath(upfile, req, "uploadImg/"+s+"/");
		  return imgPath;
      }
}
